package com.library.dao.impl;

import com.library.bean.Book;
import com.library.dao.BaseDao;
import com.library.dao.BookDao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BookDaoImpl extends BaseDao implements BookDao {

    @Override
    public List<Book> queryAll() {
        String sql = "SELECT * FROM book";
        ResultSet rs = BaseDao.queryResultSet(sql);
        List<Book> list = new ArrayList<>();
        try{
            while (rs.next()) {
                Book b = new Book();
                b.setBook_id(rs.getInt("bookId"));
                b.setBook_name(rs.getString("bookName"));
                b.setBook_type(rs.getString("type"));
                b.setBook_author(rs.getString("author"));
                list.add(b);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeAll(BaseDao.conn,BaseDao.ps,rs);
        }
        return list;
    }
}